package com.ruoyi.web.controller.operation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.GwOperationAccount;
import com.ruoyi.system.domain.GwOperationAccountRole;
import com.ruoyi.system.domain.vo.AccountRoleVO;
import com.ruoyi.system.domain.vo.OperationMenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GwOperationRole;
import com.ruoyi.system.service.IGwOperationRoleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运营角色Controller
 * 
 * @author ruoyi
 * @date 2025-05-08
 */
@Api(description = "平台运营管理-角色权限管理")
@RestController
@RequestMapping("/system/operationRole")
public class GwOperationRoleController extends BaseController
{
    @Autowired
    private IGwOperationRoleService gwOperationRoleService;

    /**
     * 查询运营角色列表
     */
    @ApiOperation("查询角色权限列表-分页")
    @GetMapping("/list")
    public TableDataInfo list(GwOperationRole gwOperationRole)
    {
        startPage();
        List<GwOperationRole> list = gwOperationRoleService.selectGwOperationRoleList(gwOperationRole);
        return getDataTable(list);
    }

    /**
     * 查询运营角色列表--无分页
     */

    @ApiOperation("查询角色权限列表-无分页")
    @GetMapping("/roleList")
    public AjaxResult roleList(GwOperationRole gwOperationRole)
    {
        List<GwOperationRole> list = gwOperationRoleService.selectGwOperationRoleList(gwOperationRole);
        return AjaxResult.success(list);
    }

    /**
     * 导出运营角色列表
     */
    @PreAuthorize("@ss.hasPermi('system:operationRole:export')")
    @Log(title = "运营角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwOperationRole gwOperationRole)
    {
        List<GwOperationRole> list = gwOperationRoleService.selectGwOperationRoleList(gwOperationRole);
        ExcelUtil<GwOperationRole> util = new ExcelUtil<GwOperationRole>(GwOperationRole.class);
        util.exportExcel(response, list, "运营角色数据");
    }

    /**
     * 获取运营角色详细信息
     */
    @ApiOperation("查询角色权限详情")
    @PreAuthorize("@ss.hasPermi('system:operationRole:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gwOperationRoleService.selectGwOperationRoleById(id));
    }

    /**
     * 新增运营角色
     */
    @ApiOperation("新增角色")
    @PreAuthorize("@ss.hasPermi('system:operationRole:add')")
    @Log(title = "运营角色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GwOperationRole gwOperationRole)
    {
        return toAjax(gwOperationRoleService.insertGwOperationRole(gwOperationRole));
    }

    /**
     * 修改运营角色
     */
    @ApiOperation("修改角色")
    @PreAuthorize("@ss.hasPermi('system:operationRole:edit')")
    @Log(title = "运营角色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwOperationRole gwOperationRole)
    {
        return toAjax(gwOperationRoleService.updateGwOperationRole(gwOperationRole));
    }

    /**
     * 删除运营角色
     */
    @ApiOperation("删除角色")
    @PreAuthorize("@ss.hasPermi('system:operationRole:remove')")
    @Log(title = "运营角色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gwOperationRoleService.deleteGwOperationRoleByIds(ids));
    }

    /**
     * 获取运营菜单
     */
    @ApiOperation("获取运营菜单列表")
    @GetMapping(value = "/operationMenuList")
    public AjaxResult operationMenuList()
    {
        List<OperationMenuVO> menuVOList = gwOperationRoleService.operationMenuList();
        return success(menuVOList);
    }

    /**
     * 根据角色查询关联人员列表--无分页
     */

    @ApiOperation("根据角色查询关联人员列表-无分页")
    @GetMapping("/accountListByRole")
    public AjaxResult accountListByRole(GwOperationRole gwOperationRole)
    {
        List<GwOperationAccount> list = gwOperationRoleService.accountListByRole(gwOperationRole);
        return AjaxResult.success(list);
    }


    /**
     * 删除关联账号
     */

    @ApiOperation("删除关联账号")
    @GetMapping("/deleteAccountFromRole")
    public AjaxResult deleteAccountFormRole(AccountRoleVO accountRoleVO)
    {
        return AjaxResult.success(gwOperationRoleService.deleteAccountFormRole(accountRoleVO));
    }

}
